package com.starlight.ts_clouddev.util;

import com.alibaba.druid.sql.visitor.functions.If;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * @Author yfy2001
 * @date 2023/6/9 14:28
 * 价格计算器
 */
@Component
public class TotalChargeCalculator {
    private static final BigDecimal cpuPrice=new BigDecimal(10);
    private static final BigDecimal memoryPrice=new BigDecimal(5);
    private static final BigDecimal storagePrice=new BigDecimal("0.05");
    private static final BigDecimal bandwidthPrice=new BigDecimal(5);
    public Long Calculate(
            Long cpu,
            Long memory,
            Long storage,
            Long bandwidth,
            Long time
    ){
        if (cpu<0){
            cpu=0L;
        }
        if (memory<0){
            memory=0L;
        }
        if (storage<0){
            storage=0L;
        }
        if (bandwidth<0){
            bandwidth=0L;
        }
        BigDecimal cpuCost=cpuPrice.multiply(new BigDecimal(cpu));
        BigDecimal memoryCost=memoryPrice.multiply(new BigDecimal(memory));
        BigDecimal storageCost=storagePrice.multiply(new BigDecimal(storage));
        BigDecimal bandwidthCost=bandwidthPrice.multiply(new BigDecimal(bandwidth));
        BigDecimal totalCharge=(cpuCost
                .add(memoryCost)
                .add(storageCost)
                .add(bandwidthCost)).multiply(new BigDecimal(time));
        return totalCharge.longValue();
    }
}
